home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / hard / hack / i2clib40.lha / i2clib40 / Intro / ReadMe.doc < prev    next >
Text File  |  1999-01-10  |  14KB  |  342 lines

  1. document i2c.library
  2.  
  3.                              i2c.library
  4.                        A Postcard-Ware Library
  5.  
  6.       © Copyright 1993-96 by GizmoSoft Productions / Brian Ipsen
  7.                  © Copyright 1997-99 by Wilhelm Nöker
  8.  
  9.                          All rights reserved.
  10.  
  11.  
  12.  
  13. 0. Disclaimer
  14. =============
  15.  
  16. The authors neither assume nor accept any responsibility for the use
  17. or misuse of this library, code or connected hardware.
  18.  
  19. The authors will not be liable for any damage arising from the failure
  20. of this library to perform as described, or any destruction of other
  21. programs or data residing on a system attempting to use the library
  22. functions. The user of this program uses it at his or her own risk.
  23.  
  24. No guarantee of any kind is given that the library described in
  25. this document is 100% reliable. You are using this material on your
  26. own risk.
  27.  
  28.  
  29.  
  30. 1. About the I2C bus
  31. ====================
  32.  
  33.  
  34. 1.1. History and background
  35. ---------------------------
  36.  
  37. An increasing number of complex integrated circuits, ranging from
  38. real-time clocks to frequency synthesizers, is provided with an I2C
  39. bus interface. Not surprisingly, the I2C bus is found in a wide
  40. variety of electronic equipment, including telephones, car radios,
  41. television sets and video recorders.
  42.  
  43. The acronym I2C stands for Inter-IC Communication, and the network was
  44. developed by Philips to reduce the number of connections between
  45. integrated circuits. This proved feasible in pratice mainly because
  46. many ICs have a large number of pins that carry information that is
  47. not time-critical and, therefore, suitable for conveying via a
  48. relatively slow serial bus with fewer connections than would be
  49. required for a high-speed parallel interface. The implementation of
  50. the I2C bus on a real-time clock chip, for instance, may reduce the
  51. number of pins from 40 to as few as 8. This results in a much simpler
  52. PCB design with all benefits of lower production cost and smaller
  53. risks of faults developing in equipment. However, a number of
  54. connections, including those for the supply voltage, for clock
  55. signals, etc., can not be replaced by a serial communication protocol.
  56. It will be clear that these connections remain necessary as before.
  57.  
  58. All ICs that use the I2C bus are in principle connected to two lines
  59. (check figure 1). A central bus interconnects two microcontrollers, a
  60. memory, a gate array and an LCD driver.
  61.  
  62. In spite of their wide diversity as regards function and appli-
  63. cation, all I2C-compatible integrated circuits have one common
  64. feature: all control commands and data are conveyed via a serial bus,
  65. according a predefined communication protocol. The serial bus takes
  66. the form of three lines: ground, clock (SCL) and data (SDA).
  67.  
  68. Normally, any I2C configuration has at least one master (an IC capable
  69. of initiating the data exchange processes and generating a master
  70. clock signal) and one or more slaves (ICs that do the actual work). A
  71. master can be a microprocessor such as an 8048, an 8051 or a 68000,
  72. which are available in special versions with a built-in I2C bus
  73. interface. Two I/O port lines of the microprocessor are used as SDA
  74. and SCL lines. Together with the ground line, this implements an I2C
  75. bus which allows serial communication between 'bused' devices at a
  76. rate of up to 100 kbit per second.
  77.  
  78. It is also possible to emulate a I2C bus master on a computer with
  79. this library and some hardware. This requires 3 lines from a port,
  80. which is for example (in case you're using the parallel interface from
  81. Jan Leuverink's TeleText package) D2, SEL and POUT.
  82.  
  83.  
  84. 1.2. Control programs
  85. ---------------------
  86.  
  87. The two communication lines, SDA and SCL, are connected to open-drain
  88. or open-collector outputs, and have one, common, pullup-resistor
  89. (check figure 2). This arrangement is called a wired AND-structure.
  90. Adding or removing one or more I2C components on the bus therefore
  91. does not affect the operation of already connected ICs, nor does it
  92. affect the software that runs on the system. In fact, the software is
  93. capable of automatic detection of the hardware configuration. This
  94. allows programs to be written for complex systems that do not provide
  95. certain features unless the relevant chips are connected to the bus.
  96. The absence of these chips is automatically detected by the master
  97. controller which interrogates certain addresses.
  98.  
  99. Existing software may be extended with subroutines written for add-on
  100. ICs without affecting the operation of the ICs already installed. This
  101. allows existing control programs to be used for a long time without
  102. the need of a completely new version every time the hardware is
  103. modified. This high level of compability is achieved by virtue of the
  104. fixed adresses of the ICs on the I2C bus.
  105.  
  106.  
  107. 1.3. Two lines
  108. --------------
  109.  
  110. Both SDA and SCL are bidirectional lines, connected to a positive
  111. supply voltage via a pull-up resistor (see figure 2). When all output
  112. transistors of connected devices are off, the bus is free, and both
  113. lines are high. When an IC is ready to transmit a data block, it pulls
  114. SDA low to mark a start condition. From that moment, all other ICs
  115. 'know' that the bus is in use. Arbitration procedures come into effect
  116. should one or more ICs claim access to the bus simultaneously. When
  117. the start condition is recognized, the SDA line is available for
  118. carrying databits. The clock line, SCL, determines the validity of the
  119. data levels on the SDA line (check figure 3).
  120.  
  121. The start of any data exchange via the bus is marked by SDA going low
  122. while SCL is high, i.e., by a start condition (check figure 4). The
  123. level on the SDA line is read by all ICs on the bus during the
  124. positive part of the clock pulse. However, only the IC selected by the
  125. transmitted address-code responds to the information by actually
  126. loading the data and returning an acknowledge pulse. This pulse is
  127. generated by the addressed slave device by pulling the data line low
  128. for one clock period after the eight clock periods reserved for the
  129. databits (check figure 4).
  130.  
  131. When none of the ICs in the system responds to the transmitted data,
  132. the master does not receive an acknowledge pulse. This means that
  133. either the addressed slave is busy performing some real-time function,
  134. the address is wrong or there is no device that responds at that
  135. particular address. The bus is free again after the transmission of
  136. the last data bit. Both SCL and SDA revert to high, and the bus may be
  137. used to convey the next data block.
  138.  
  139. The function of the SCL line is to generate one clock pulse for every
  140. transmitted databit. Each master must generate its own SCL signal.
  141. Although the frequency of this signal is not fixed, certain minimum
  142. timing specifications must be preserved. In practice, the I2C bus
  143. allows a maximum data speed of about 100 Kbit/s.
  144.  
  145.  
  146. 1.4. Adressing
  147. --------------
  148.  
  149. Each IC on the I2C bus has its own, unique 7-bit address, which is
  150. determined by the manufacturer and hard-coded into the chip. The type
  151. PCF8583 real-time clock chip for example, is selected by sending
  152. binary code 101000x. The last bit is user-preset (x is 0 or 1) to
  153. allow two identical ICs to be used in parallel by tying their inputs
  154. to ground or the positive supply to set the address to 1010000 or
  155.  1010001 respectively. Similary, certain ADCs, DACs chips and memories
  156. may be hard-wired to map them at one of up to eight adresses in a
  157. cluster.
  158.  
  159. The data clock conveyed via the bus invariably consist of 8 bits. The
  160. bit that follows the address indicates the start of a read or write
  161. operation with the selected IC. Bit 8 is low for a write operation,
  162. and high for a read operation.
  163.  
  164.  
  165. 1.5. Applications
  166. -----------------
  167.  
  168. There is much more to the concept of the I2C bus than can be described
  169. here. The full specification of the system may be found in the I2C-bus
  170. Specifications by Philips Components. The I2C bus is relatively simple
  171. to implement on almost any microcomputer system that has at least one
  172. user port. If nessecery, external buffers may have to be added to make
  173. such a port bidirectional. Some microcomputers, including the Acorn
  174. Archimedes, even have an I2C interface a a standard feature.
  175. Developers of small stand-alone microprocessor systems may find the
  176. I2C version of the 8048, the PCF84C00T, a good starting point for the
  177. design of a dedicated control system.
  178.  
  179.  
  180.  
  181. 2. About the Library
  182. ====================
  183.  
  184.  
  185. 2.1. Using i2c.library
  186. ----------------------
  187.  
  188. Using the library should not be that complicated. Take a look at the
  189. AutoDoc file (named i2c.doc) for the library and at the example-code.
  190. This should give you enough hints on how to use the supplied routines.
  191.  
  192. In case you're not much of a programmer, but a hardware hobbyist, you
  193. will probably like the contents of the "bin" directory: "SendI2C" and
  194. "ReceiveI2C" are simple Shell commands for controlling and querying
  195. I2C chips. And there's "I2Cscan", a diagnostic tool which should be
  196. useful for everyone (and is in fact even invoked from the installer
  197. script).
  198.  
  199.  
  200. 2.2. Library limitations
  201. ------------------------
  202.  
  203. As you may recall from earlier chapters, I2C-bus clock timing isn't
  204. really critical or something. However, the I2C-bus specification by
  205. Philips describes that the maximum clock rate for SCL is 100 kHz.
  206. Exceed that speed, and your chips don't reply any more, that's a fact.
  207.  
  208. The problem is that i2c.library design was always aimed at a good
  209. utilisation of this maximum bandwidth, and the solution was to make
  210. timing adjustable, rather than simply reliable. (Reliable would have
  211. meant using timer.device, which gives a hopelessly huge overhead when
  212. it comes to 5 microsecond intervals.) This has turned out to be a
  213. major reason for confusion among first-time users.
  214.  
  215. Adjustable timing means for you as an end user, that you need to know
  216. a timing parameter suitable for your system. (Hint: try 5 for A1200, 1
  217. for all other Amigas, or simply 10 to be really on the safe side.) The
  218. installer script will ask you for this parameter, will test it (if
  219. possible) and store it in an environment variable (I2CDELAY).
  220.  
  221. Note that application programs may still override this environment
  222. value, and many actually do (Wilhelm Nöker's "VideoText" for example).
  223. This is because up until i2clib v39, if an application didn't adjust
  224. the I2C clock timing, no one else would. This was poorly designed,
  225. sorry, but that's how it worked. So just don't be surprised if
  226. sometimes, for these historical reasons, you will have to enter the
  227. timing parameter for your system in more than one place.
  228.  
  229.  
  230. 2.3. History
  231. ------------
  232.  
  233. i2c.library came into being a while ago in connection with a hardware
  234. project named TeleText (see hard/hack/tt120.lha on Aminet). As can
  235. still be seen from those documents, Jan Leuverink was planning to
  236. implement the I2C-bus routines for his program in a shared library.
  237. However, Brian Ipsen, who helped him with testing at that time,
  238. apparently was faster (or had more time) and was the one to actually
  239. write the library.
  240.  
  241. Since those days, i2c.library has undergone quite a few changes. As of
  242. v39.0, these changes have been made by Wilhelm Nöker.
  243.  
  244.  
  245.    v40.0
  246.      - Configuration by I2CDELAY environment variable
  247.      - I2C_Base exports performance counters and some interface type
  248.        information
  249.  
  250.    v39.4
  251.      - Bugfix: Misplaced delay loops would slow down the overall clock
  252.        rate, but would not resolve all timing problems.
  253.      - Better version string
  254.  
  255.    v39.2
  256.      - Protected SendI2C / ReceiveI2C by a semaphore, so that more than
  257.        one client at a time can use the library. (Useful for I²C buses
  258.        with more than one chip attached.)
  259.      - Made functions AllocI2C, InitI2C, FreeI2C obsolete.
  260.      - Replaced bus timing by timer.device / by empty loops
  261.        with timing by loops of CIA read accesses.
  262.      - SendI2C / ReceiveI2C return more detailed error codes.
  263.      - SendI2C / ReceiveI2C ignore the supplied R/W address bit and set
  264.        it to its proper value.
  265.      - Added functions I2CErrText, ShutDownI2C, BringBackI2C.
  266.  
  267.    v38.0
  268.      - Added function GetI2COpponent.
  269.  
  270.    v37.2
  271.      - Moved code to set timerdelay to zero into the library initcode.
  272.  
  273.    v37.1
  274.      - First official release
  275.  
  276.  
  277.  
  278. 3. About the Authors
  279. ====================
  280.  
  281.  
  282. 3.1. Who did it?
  283. ----------------
  284.  
  285. Original library design and documentation by Brian Ipsen.
  286.  
  287.     Brian Ipsen                 bipsen@usa.net
  288.     Ved Andebakken 10, 4.tv.    fido: 2:238/67.97
  289.     DK-2000 Frederiksberg
  290.     Denmark
  291.  
  292. Current binary implementations by Wilhelm Nöker.
  293.  
  294.     Wilhelm Nöker               wnoeker@t-online.de
  295.     Hertastr. 8
  296.     D-44388 Dortmund
  297.     Germany
  298.  
  299.  
  300. 3.2. Where Are They Now?
  301. ------------------------
  302.  
  303. Brian Ipsen:
  304.  
  305.     His Amiga unfortunately almost died around February 1st, 1996.
  306.     Since that time he hasn't used it much, but instead jumped to a
  307.     Pentium-based PC, which he's currently using. No plans about
  308.     upgrading/repairing the Amiga (unless he sees a pretty good price
  309.     on a working A2000 motherboard or a cheap A4000 :-)).
  310.  
  311. Wilhelm Nöker:
  312.  
  313.     Incorrigible Amiga user, however with a daytime job that involves
  314.     writing device drivers for Windows 95/NT. %-|
  315.  
  316.  
  317. 3.3. License
  318. ------------
  319.  
  320. Using i2c.library in a commercial or shareware project will require
  321. explicit permission from Wilhelm Nöker. (Permission will most likely
  322. be granted in exchange for a keyfile or a fully functional copy of the
  323. finished product.)
  324.  
  325. Using i2c.library in a non-commercial project, no matter if it is to
  326. be published or not, will require a short thank-you message, either
  327. postcard or e-mail, to either Brian Ipsen or Wilhelm Nöker.
  328.  
  329.  
  330. 3.4. Acknowledgements
  331. ---------------------
  332.  
  333. This guide file was created using Text2Guide by Stephan Sürken.
  334.  
  335. Thanks to Thorsten Marquardt <thom@kaupp.chemie.uni-oldenburg.de>,
  336. who made the Maxon include files.
  337.  
  338. And thanks goes especially to Jan Leuverink, whose work got all this
  339. started.
  340.  
  341.  
  342.